//
//  ShellPledgeViewController.m
//  ShellWallert
//
//  Created by lvzhao on 2019/9/27.
//  Copyright © 2019年 VV. All rights reserved.
//

#import "ShellPledgeViewController.h"
#import "ShellPledgeView.h"
#import "ShellPledgeViewModel.h"
#import "ShellIncomeStatementView.h"  //收益说明

@interface ShellPledgeViewController ()
@property (nonatomic,strong) ShellPledgeView *pledgeView;

@property (nonatomic,strong) ShellPledgeViewModel *viewModel;

@end

@implementation ShellPledgeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = LZLocalizedString(@"质押");
    
    [self setupUI];
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.barTintColor = COLOR_TINT;
}



#pragma mark - setupUI
- (void)setupUI{
    
    [self.view addSubview:self.pledgeView];
    [self.pledgeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
    
    ///!!!:收益说明
    UIButton *descriptionBtn = [UIButton lz_buttonTitle:LZLocalizedString(@"收益说明") titleColor:UIColorHex(0xFFFFFF) fontSize:14];
    [self initBarItem:descriptionBtn withType:1];
    
    [[descriptionBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
       
        [ShellIncomeStatementView show];
    }];
    
    [self.viewModel pledgeData];
    
    
    //当前时间戳
    NSInteger newTimestamp = [NSDate cTimestampFromDate:[NSDate date]];
    
    
    //2019-11-01 09:00:00
    NSDate *pledgeDate = [NSDate dateFromString:@"2019-11-01 09:00:00" format:@"yyyy-MM-dd HH:mm:ss"];
    NSInteger pledgeTimestamp = [NSDate cTimestampFromDate:pledgeDate];

    
    if(newTimestamp < pledgeTimestamp){
           @weakify(self);
           [LZToolView showAlertType:LZAlertViewTypPledgeTime withTitle:LZLocalizedString(@"提示") message:LZLocalizedString(@"2019-11-01 09:00:00 开放") cancel:@"" sure:LZLocalizedString(@"确定") objectDict:@{} cancelBlock:nil sureBlock:^(id  _Nullable object) {
               @strongify(self);
               [self.navigationController popViewControllerAnimated:YES];
           }];
    }
    
    
    
    
   
    
    
    
}

#pragma mark - actions

#pragma mark - custool

#pragma mark - get && set
- (ShellPledgeView *)pledgeView{
    
    if(!_pledgeView){
        _pledgeView = [[ShellPledgeView alloc] initViewModel:self.viewModel];
    }
    return _pledgeView;
}

- (ShellPledgeViewModel *)viewModel{
    if(!_viewModel){
        _viewModel = [[ShellPledgeViewModel alloc] init];
        
    }
    return _viewModel;
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
